//
//  GRPersonAction.m
//  YC_GRice
//
//  Created by LiuFeng on 2018/7/8.
//  Copyright © 2018年 YeCai. All rights reserved.
//

#import "GRPersonAction.h"
#import "GRPersonModel.h"
#import "GRCollectionModel.h"

@interface GRPersonAction ()


@end

@implementation GRPersonAction

+ (void)getMemberShipInfomation:(RequestBlock)completionHandler {
    NSString *url = [NSString stringWithFormat:@"%@userPoint/v1/userPageData",GRiceAPI];
    
    [RequestManager MembershipRequestWithURLString:url Method:GR_GET Paramers:nil completionHandler:^(BOOL success, id responseObject, GRError *error) {
        completionHandler(success, responseObject, error);
    }];
}

+ (void)getUserProfile:(RequestBlock)completionHandler {
    NSString *url = [NSString stringWithFormat:@"%@gmUser/info",GRDeliveryAPI];
    
    [RequestManager MembershipRequestWithURLString:url Method:GR_GET Paramers:nil completionHandler:^(BOOL success, id responseObject, GRError *error) {
        if (success) {
            GRPersonModel *model = [GRPersonModel yy_modelWithDictionary:responseObject];
            completionHandler(YES, model, nil);
        }else {
            completionHandler(NO, nil, error);
        }
    }];
}

+ (void)updateUserProfile:(NSDictionary *)paramer completionHandler:(RequestBlock)completionHandler {
    NSString *url = [NSString stringWithFormat:@"%@gmUser/update",GRDeliveryAPI];
    
    [RequestManager MembershipRequestWithURLString:url Method:GR_POST Paramers:paramer completionHandler:^(BOOL success, id responseObject, GRError *error) {
        completionHandler(success, responseObject, error);
    }];
}

+ (void)bindingWechat:(BOOL)isBind paramer:(NSDictionary *)paramer completionHandler:(RequestBlock)completionHandler {
    NSString *path = isBind ? @"gmUser/wechat/bind" : @"gmUser/wechat/unbind";
    NSString *url  = [NSString stringWithFormat:@"%@%@",GRDeliveryAPI, path];
    
    [RequestManager MembershipRequestWithURLString:url Method:GR_POST Paramers:paramer completionHandler:^(BOOL success, id responseObject, GRError *error) {
        completionHandler(success, responseObject, error);
    }];
}


+ (void)bindingAlipay:(BOOL)isBind paramer:(NSDictionary *)paramer completionHandler:(RequestBlock)completionHandler {
    NSString *path = isBind ? @"gmUser/alipay/bind" : @"gmUser/alipay/unbind";
    NSString *url  = [NSString stringWithFormat:@"%@%@",GRDeliveryAPI, path];
    
    [RequestManager MembershipRequestWithURLString:url Method:GR_POST Paramers:paramer completionHandler:^(BOOL success, id responseObject, GRError *error) {
        completionHandler(success, responseObject, error);
    }];
}

+ (void)getAlipayAuth_V2Str:(RequestBlock)completionHandler {
    NSString *url = [NSString stringWithFormat:@"%@gmUser/alipayAuthString",GRDeliveryAPI];
    
    [RequestManager MembershipRequestWithURLString:url Method:GR_GET Paramers:nil completionHandler:^(BOOL success, id responseObject, GRError *error) {
        completionHandler(success, responseObject, error);
    }];
}


+ (void)getMyRiceInfomation:(RequestBlock)completionHandler {
    NSString *url = [NSString stringWithFormat:@"%@userPoint/v1/getUserPoint",GRiceAPI];
    
    [RequestManager MembershipRequestWithURLString:url Method:GR_GET Paramers:nil completionHandler:^(BOOL success, id responseObject, GRError *error) {
        completionHandler(success, responseObject, error);
    }];
}

+ (void)getMyCollection:(NSDictionary *)paramer completionHandler:(RequestBlock)completionHandler {
    NSString *url = [NSString stringWithFormat:@"%@v1/collection/list",GRiceAPI];
    
    [RequestManager MembershipRequestWithURLString:url Method:GR_POST Paramers:paramer completionHandler:^(BOOL success, id responseObject, GRError *error) {
        if (success) {
            NSArray *array = responseObject[@"dataList"];
            NSMutableArray *collections = [NSMutableArray array];
            for (NSDictionary *dic in array) {
                GRCollectionModel *model = [GRCollectionModel yy_modelWithDictionary:dic];
                [collections addObject:model];
            }
            completionHandler(YES, collections, nil);
        }else {
            completionHandler(NO, nil, error);
        }
    }];
}


+ (void)deleteCollectionWithID:(NSInteger)collectionId completionHandler:(RequestBlock)completionHandler {
    NSString *url = [NSString stringWithFormat:@"%@v1/collection/delete/%ld",GRiceAPI, collectionId];
    
    [RequestManager MembershipRequestWithURLString:url Method:GR_GET Paramers:nil completionHandler:^(BOOL success, id responseObject, GRError *error) {
        completionHandler(success, responseObject, error);
    }];
}

+(void)IntegralGive:(NSDictionary *)dic  completionHandler:(RequestBlock)completionHandler{
    NSString * path =  [NSString stringWithFormat:@"%@userPoint/shiftPoint",GRiceAPI];
    [RequestManager MembershipRequestWithURLString:path Method:GR_POST Paramers:dic completionHandler:^(BOOL success, id responseObject, GRError *error) {
        completionHandler(success, responseObject, error);
    }];
}

+(void)getUserPointLogList:(NSDictionary * )dic CallBack:(RequestBlock)callBack {
    
    NSString *url = [NSString stringWithFormat:@"%@userPoint/getUserPointLogList",GRiceAPI];
    [RequestManager MembershipRequestWithURLString:url Method:GR_POST Paramers:dic completionHandler:^(BOOL success, id responseObject, GRError *error) {
        callBack(success, responseObject, error);
    }];
    
}

@end
